/* Copyright 2001,2002,2003 NAH6 BV
 * All Rights Reserved
 *
 *  $Header: /var/lib/cvs/secphone/ui/phone/VolumeManager.h,v 1.8 2003/11/21 12:39:24 itsme Exp $
 *
 *
 */


#ifndef __VOLUMEMANAGER_H__

#include "nhthread.h"

enum {
    EV_VMGR_RING,
    EV_VMGR_TIMER,
    EV_VMGR_VOICECONNECT,
    EV_VMGR_PHONEDISCONNECT,
    EV_VMGR_RILDISCONNECT,
    EV_VOLUME_UPDATE,
    VOLUME_NR_OF_EVENTS
};

class VolumeManager : public NHThread {
public:
    VolumeManager();
    virtual ~VolumeManager();

    virtual void StartThread();

    // this method is called from the ipc handler to report back volume readings
    void UpdateCurrentVolume(DWORD volume);

    bool UpdateState(int event);

    void SignalRinging();
    void SignalRingon();
    void SignalVoiceConnect();
    void SignalPhoneDisconnect();
    void SignalRILDisconnect();


    void EnableTimer();
    void DisableTimer();
    static void CALLBACK staticTimerProc(HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime);
    void TimerProc(HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime);

    void IncreaseVolume();
    void DecreaseVolume();

protected:
    virtual DWORD ThreadProc();
    virtual const char* name() const { return "VolumeManager"; }

public:
    void mainloop();

private:
        HANDLE      m_hEvents[VOLUME_NR_OF_EVENTS];
        DWORD       m_dwCurrentVolume;
        DWORD       m_dwCurrentWait;
        int         m_state;
        CRITICAL_SECTION m_lock;
        int         m_nVolumeOffset;
        int         m_nTimerCount;

    int WaitState(DWORD eventMask);

    void Reset();

    bool SaveStateVolume(int state);
    void LoadStateVolume(int state);
    void LoadIdleVolume();
    void SaveIdleVolume();
    void LoadRingVolume();
    void SaveRingVolume();
    void LoadTalkVolume();
    void SaveTalkVolume();

    int GetStateMaximum();
    int GetStateMinimum();
};

#define __VOLUMEMANAGER_H__
#endif

